/**
 * Created by JiaJia on 2019/6/10 0010.
 */
public class Code57 {
    public static class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }
    public static ListNode deleteDuplication(ListNode pHead) {
        if (pHead==null)
            return null;
        //新建一个头结点
        ListNode first=new ListNode(-1);
        first.next=pHead;
        ListNode p=pHead;
        ListNode pre=first;

        while (p != null && p.next != null) {
            if (p.val == p.next.val) {
                int val = p.val;// 向后重复查找
                while (p != null && p.val == val) {
                    p = p.next;
                } // 上个非重复值指向下一个非重复值：即删除重复值
                pre.next = p;
            }else {// 如果当前节点和下一个节点值不等，则向后移动一位
                pre= p;
                p = p.next;
            }
        }
        return first.next;
    }
}